package com.abc.robot01

import android.content.Intent
import com.abc.robot01.activity.DemoActivity
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
    // This value must match the `MethodChannel` name in your Dart code.
    private val CHANNEL = "com.example.flutter_android_activity"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
                call: MethodCall, result: MethodChannel.Result ->
            when (call.method) {
                // Note: This must match the first parameter passed to
                // `platformMethodChannel.invokeMethod` in your Dart code.
                "launchActivity" -> {
                    try {
                        // Takes an object, in this case a String.
                        val message = call.arguments
                        val intent = Intent(this@MainActivity, DemoActivity::class.java)
                        intent.putExtra("message", message.toString())
                        startActivity(intent)
                    } catch (e: Exception){}
                    result.success(true)
                }
                else -> {}
            }
        }
    }
}
